//
//  UIImage+Extension.swift
//  Weibo(Swift)
//
//  Created by 肖霆 on 16/5/21.
//  Copyright © 2016年 肖霆. All rights reserved.
//

import UIKit

extension UIImage{

    //压缩图片的方法
    func scaleImageWithWidth(scaleWidth:CGFloat)->UIImage{
        let scaleHeight = scaleWidth/self.size.width * self.size.height
        let size = CGSizeMake(scaleWidth, scaleHeight)
        //开启上下文
        UIGraphicsBeginImageContext(size)
        //把图片绘制到指定区域
        self.drawInRect(CGRect(origin: CGPointZero, size: size))
        //获取压缩后的图片
        let scaleImage = UIGraphicsGetImageFromCurrentImageContext()
        //关闭上下文
        UIGraphicsEndImageContext()
        
        return scaleImage
    }

}
